// Fill out your copyright notice in the Description page of Project Settings.


#include "MotionSubtitlesCanvas.h"


AMotionSubtitlesCanvas::AMotionSubtitlesCanvas()
{
	PrimaryActorTick.bCanEverTick = true;

	USceneComponent* SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	SetRootComponent(SceneComponent);

	PostProcessComponent = CreateDefaultSubobject<UPostProcessComponent>(TEXT("PostProcess"));
	PostProcessComponent->SetupAttachment(GetRootComponent());
}

void AMotionSubtitlesCanvas::Add(const FGuid Id, TWeakObjectPtr<UMaterialInstanceDynamic> Material)
{
	if (Mappings.Contains(Id))
	{
		return;
	}
	
	Mappings.Add(Id, Material);
	PostProcessComponent->Settings.AddBlendable(Material.Get(),1);
}

void AMotionSubtitlesCanvas::Remove(const FGuid Id)
{
	if (!Mappings.Contains(Id))
	{
		return;
	}

	const TWeakObjectPtr<UMaterialInstanceDynamic> Material = Mappings[Id];
	PostProcessComponent->Settings.RemoveBlendable(Material.Get());
}
